SOGetAddrInfo


C Specification

#include <dolphin/socket.h>
  
typedef struct SOAddrInfo   SOAddrInfo;
struct SOAddrInfo
{
    int             flags;         // input flags
    int             family;        // address family of socket
    int             sockType;      // socket type
    int             protocol;      // protocol of socket
    unsigned        addrLen;       // length of socket address
    char*           canonName;     // canonical name of service location
    void*           addr;          // socket address of socket
    SOAddrInfo*     next;          // pointer to next in list
};

// SOAddrInfo{}.flags
#define SO_AI_PASSIVE       0x01
#define SO_AI_CANONNAME     0x02
#define SO_AI_NUMERICHOST   0x04
#define SO_AI_NUMERICSERV   0x08

#define SO_EAI_AGAIN        -300
#define SO_EAI_BADFLAGS     -301
#define SO_EAI_FAIL         -302
#define SO_EAI_FAMILY       -303
#define SO_EAI_MEMORY       -304
#define SO_EAI_NONAME       -305
#define SO_EAI_SERVICE      -306
#define SO_EAI_SOCKTYPE     -307
#define SO_EAI_SYSTEM       -308
#define SO_EAI_OVERFLOW     -309

int   SOGetAddrInfo( const char* nodeName, const char* servName,
                     const SOAddrInfo* hints, SOAddrInfo** res );

Description

SOGetAddrInfo() translates a node name and/or a service name to a set of socket addresses. SOGetAddrInfo() is thread-safe.

Arguments

nodeName Pointer to an address string or NULL. Valid name is either a host name or a dotted notation of an address. If nodeName is NULL, SOGetAddrInfo() locates the service of the local host.
servName Pointer to a string specifying a decimal port number or NULL. If servName is NULL, SOGetAddrInfo() returns an IP address for the specified nodeName.
hints Pointer to a SOAddrInfo structure or NULL. If hints is not NULL, every structure member other than flags, family, sockType, and protocol should be zero-cleared before the function call.
 
flags Zero or the bitwise OR of the following values:
 
SO_AI_PASSIVE If nodeName is not NULL, SO_AI_PASSIVE is ignored. Otherwise, if SO_AI_PASSIVE is set, nodeName is treated as "0.0.0.0"(SO_INADDR_ANY). If SO_AI_PASSIVE is not set, nodeName is treated as "127.0.0.1" (SO_INADDR_LOOPBACK).
SO_AI_CANONNAME If nodeName is not NULL, SOGetAddrInfo() attempts to obtain the canonical name corresponding to nodeName.
SO_AI_NUMERICHOST Specifies a numeric host address string to nodeName. Otherwise, SO_EAI_NONAME is returned. No DNS resolution is taken.
SO_AI_NUMERICSERV Specifies a numeric port number string to servName. Otherwise, SO_EAI_NONAME is returned. No DNS resolution is taken.
family Valid family is either SO_AF_INET or SO_AF_UNSPEC.
sockType Specifies the socket type to be used as defined in  SOSocket(). If zero is specified, SOGetAddrInfo() attempts to resolve the service name for all possible socket types.
protocol Specified the protocol to be used as defined in  SOSocket(). If zero is specified, SOGetAddrInfo() attempts to resolve the service name for all possible protocols.
res Upon successful completion, res refers to the head of of a linked list of SOAddrInfo structure. Each SOAddrInfo structure has the following fields:
 
flags Zero.
family Address family for use with SOSocket().
sockType Socket type for use with SOSocket().
protocol Protocol for use with SOSocket().
canonName If SO_AI_CANONNAME is requested, canonName of the first SOAddrInfo structure points to the canonical name corresponding to nodeName. If the canonical name is not available, canonName point to a string with the same contents as nodeName.
addr Pointer to a socket address structure for use with SOConnect() or SOBind().
next Pointer to the next structure on the list, or NULL if it is the last element on the list.

The retrieved linked list no longer in use must be freed with SOFreeAddrInfo().

Return Values

zero Succeeded.
SO_EAI_AGAIN Name could not be resolved. Future attempt may succeed.
SO_EAI_BADFLAGS Specified flags is invalid.
SO_EAI_FAIL A non-recoverable error occurred.
SO_EAI_FAMILY Unknown address family.
SO_EAI_MEMORY Memory allocation failure. SOGetAddrInfo() invokes SOConfig{}.alloc function to construct the linked list of SOAddrInfo structures that is passed to res.
SO_EAI_NONAME Name could not be resolved.
SO_EAI_SERVICE Unknown service name.
SO_EAI_SOCKTYPE Unknown socket type.
SO_EAI_SYSTEM A system error occurred.

See Also

SOGetHostByName(), SOFreeAddrInfo()